import java.net.MalformedURLException;
import java.net.*;
import java.security.cert.Certificate;
import java.io.*;
import java.util.*;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLPeerUnverifiedException;

public class HttpsClient{

    public static void main(String[] args)
    {
        new HttpsClient().testIt();
    }

    private static Proxy proxy;

    // FUNÇÕES
    private static void testProxy() {
        try {
            System.setProperty("java.net.useSystemProxies","true");
            List l = ProxySelector.getDefault().select( new URI("http://www.yahoo.com/"));
            for (Iterator iter = l.iterator(); iter.hasNext(); ) {

                proxy = (Proxy) iter.next();
                //System.out.println("proxy hostname : " + proxy.type());

                InetSocketAddress addr = (InetSocketAddress) proxy.address();

                if(addr == null) {
                    System.out.println("Sem Proxy");
                } else {
                    SocketAddress enderecoProxy = new InetSocketAddress("192.168.1.1",  3128);
                    proxy = new Proxy(Proxy.Type.HTTP, enderecoProxy);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void testIt(){
        testProxy();
        String https_url = "http://e-gov.betha.com.br";//"https://www.google.com/";
        URL url;
        try {
            
            Util a = new Util();

            url = new URL(https_url);
            HttpsURLConnection con = (HttpsURLConnection)url.openConnection( proxy);

            //dumpl all cert info
            a.print_https_cert(con);

            //dump all the content
            //a.print_content(con);

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}